import { baseCategoryList, getBannerList, getFloorList } from "@/api";

const state = {
    baseCategoryList: [],
    banners: [],
    floors: []
}

const mutations = {
    SetCategoryList(state, val) {
        state.baseCategoryList = val
    },
    SetBanners(state, val) {
        state.banners = val
    },
    SetFloors(state, val) {
        state.floors = val
    }
}

const actions = {
    async getCategoryList({ commit }) {
        let result = await baseCategoryList()
        if (result.code == '200') {
            commit('SetCategoryList', result.data.slice(0, 16))
        } else {
            return
        }

    },
    async getBanners({ commit }) {
        let result = await getBannerList()
        if (result.code == '200') {
            commit('SetBanners', result.data)
        } else {
            return
        }
    },

    async getFloors({ commit }) {
        let result = await getFloorList()
        if (result.code == '200') {
            commit('SetFloors', result.data)
        } else {
            return
        }
    }
}

const getters = {}

export default {
    namespaced: true,	// 开启命名空间
    state, mutations, actions, getters
}
